<?php
if($auth->isLogged())
{
	header("Location: index.html");
}
else
{
	if(isset($_POST) && !empty($_POST))
	{
		var_dump($_POST);
		$auth->login($_POST['login'],$_POST['passwd']);
		if(!$auth->error)
		{
			header("Location: index.html");
		}
		else
		{
			switch($auth->getErrorType())
			{
				case 1:
					$view['error'] = 'Identifiant incorrect';
					break;
				case 2:
					$view['error'] = 'Mot de passe incorrect';
					break;
				case 3 :
					$view['error'] = 'Impossible de contacter la base d\'utilisateurs';
					break;
				default:
					$view['error'] = 'Une erreur est survenue';
					break;
			}
			$template = $twig->loadTemplate('admin/login.html');
			echo $template->render($view);
		}
	}
	else
	{
		$template = $twig->loadTemplate('admin/login.html');
		echo $template->render($view);
	}
}
?>